package xFGE.xDisplay.xUI
{
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class xTips extends Sprite
	{
		private var _backGround:MovieClip;
		
		private var _tips:TextField;
		
		private var _defaultWidth:Number;
		
		private var _defaultHeight:Number;
		
		private var _parent:DisplayObjectContainer;
		
		public function xTips()
		{
			initView();
		}
		
		private function initView():void
		{
			_backGround = getChildByName("__backGround")as MovieClip;
			if(_backGround== null) throw(new Error("不存在__backGround:MovieClicp"));
			_tips = getChildByName("__tips") as TextField;
			_tips.autoSize = TextFieldAutoSize.CENTER;
			_tips.wordWrap = true;
			_tips.multiline= true;
			_tips.selectable = false;
			if(_tips == null) throw(new Error("不存在__tips:TextFiled"));
			//AutoSize();
		}
		
		/**
		 * 弹出 
		 * @param tips
		 * @param parent
		 * 
		 */
		public  function Popup(tips:String,parent:DisplayObjectContainer,x:int =0,y:int = 0,style:StyleSheet = null):void
		{
			_tips.styleSheet = style;
			_tips.htmlText = tips;
			_parent = parent;
			_parent.addChild(this);
			this.x = x; this.y = y;
			AutoSize();
		}
		
		/**
		 * 关闭tips 
		 * 
		 */
		public function Close():void
		{
			if(_parent.contains(this))
				_parent.removeChild(this);
		}
		
		/**
		 *  自适应大小
		 * @return 
		 * 
		 */
		private function AutoSize():void
		{
			var tipsRect:Rectangle = _tips.getRect(_backGround);
			_backGround.width = tipsRect.x*2+ _tips.width;
			_backGround.height = tipsRect.y*2+ _tips.height;
		
		}
	}
}